package dynamic.mybatisplus.core.injector.methods;



import com.baomidou.mybatisplus.core.enums.SqlMethod;
import dynamic.DynamicEntity;
import dynamic.ibatis.mapping.DMappedStatement;
import dynamic.ibatis.mapping.DSqlSource;
import dynamic.metadata.DTableInfo;
import dynamic.metadata.EntityClass;
import dynamic.mybatisplus.core.injector.DAbstractMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 查询满足条件一条数据，为了精简注入方法，该方法采用 list.get(0) 处理后续不再使用
 *
 * @author hubin
 * @since 2018-04-06
 */
@Deprecated
public class SelectOne extends DAbstractMethod {

    public SelectOne() {
        this(SqlMethod.SELECT_ONE.getMethod());
    }

    /**
     * @param name 方法名
     * @since 3.5.0
     */
    public SelectOne(String name) {
        super(name);
    }

    @Override
    public DMappedStatement injectMappedStatement(Class<?> mapperClass, EntityClass modelClass, DTableInfo tableInfo) {
        SqlMethod sqlMethod = SqlMethod.SELECT_ONE;
        DSqlSource sqlSource = super.createSqlSource(configuration, String.format(sqlMethod.getSql(),
                sqlFirst(), sqlSelectColumns(tableInfo, true), tableInfo.getTableName(),
                sqlWhereEntityWrapper(true, tableInfo), sqlComment()), DynamicEntity.class);
        return this.addSelectMappedStatementForTable(mapperClass, methodName, sqlSource, tableInfo);
    }
}

